package com.guoyh.bilbase.widget.state

import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.guoyh.bilbase.R
import com.guoyh.baseutils.ext.clickNoRepeat
import com.ruffian.library.widget.RTextView
import com.zy.multistatepage.MultiState
import com.zy.multistatepage.MultiStateContainer

open class MStateCommon : MultiState() {
    override fun onCreateMultiStateView(
        context: Context,
        inflater: LayoutInflater,
        container: MultiStateContainer
    ): View {
        return inflater.inflate(R.layout.state_layout, container, false)
    }

    private lateinit var tvState: TextView
    private lateinit var btnState: RTextView
    private lateinit var imgState: ImageView

    override fun onMultiStateViewCreate(view: View) {
        tvState = view.findViewById(R.id.mStateTv)
        btnState = view.findViewById(R.id.mStateBtn)
        imgState = view.findViewById(R.id.mStateImg)

        btnState.clickNoRepeat {
            btnClick?.invoke()
        }
    }

    fun setTv(msg: String) {
        tvState.setText(msg)
    }

    fun setImg(drawable: Drawable) {
        imgState.setImageDrawable(drawable)
    }


    private var btnClick: (() -> Unit)? =null

    fun setBtn(btns: String,btnClick:()->Unit) {
        this.btnClick = btnClick
        btnState.visibility = View.VISIBLE
        btnState.text = btns
    }


    override fun enableReload() = false

}